/*
 * Powered By [leyvi]
 * Since 2014 - 2015
 */


var like = {};
var common = require('../../utils/commonUtils');
//db转换成model
like.dbConvertModel = function(db){
	var like = {}; 
	if(common.isNotBlank(db.id)) like.id = db.id;	
	if(common.isNotBlank(db.article_id)) like.articleId = db.article_id;	
	if(common.isNotBlank(db.member_id)) like.memberId = db.member_id;	
	if(common.isNotBlank(db.status)) like.status = db.status;	
	if(common.isNotBlank(db.create_time)){
		like.createTime = db.create_time;
		like.createTimeStr = db.create_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.update_time)){
		like.updateTime = db.update_time;
		like.updateTimeStr = db.update_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.bak1)) like.bak1 = db.bak1;	
	if(common.isNotBlank(db.bak2)) like.bak2 = db.bak2;	
	if(common.isNotBlank(db.bak3)) like.bak3 = db.bak3;	
	if(typeof db.bak4 != "undefined") like.bak4 = db.bak4;
	if(typeof db.bak5 != "undefined") like.bak5 = db.bak5;
	return like;
};

//model转换成db
like.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.id = obj.id;
	if(common.isNotBlank(obj.articleId)) db.article_id = obj.articleId;
	if(common.isNotBlank(obj.memberId)) db.member_id = obj.memberId;
	if(common.isNotBlank(obj.status)) db.status = obj.status;
	if(common.isNotBlank(obj.createTime)) db.create_time = obj.createTime;
	if(common.isNotBlank(obj.updateTime)) db.update_time = obj.updateTime;
	if(common.isNotBlank(obj.bak1)) db.bak1 = obj.bak1;
	if(common.isNotBlank(obj.bak2)) db.bak2 = obj.bak2;
	if(common.isNotBlank(obj.bak3)) db.bak3 = obj.bak3;
	if(typeof obj.bak4 != "undefined") db.bak4 = obj.bak4;
	if(typeof obj.bak5 != "undefined") db.bak5 = obj.bak5;
	return db;
};

like.initPostReq = function(req){
	var like = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (like.id = req.body.id) : (like.id = req.body.id.trim());
	}
	if(req.body.articleId != undefined){
		(typeof req.body.articleId != 'string') ? (like.articleId = req.body.articleId) : (like.articleId = req.body.articleId.trim());
	}
	if(req.body.memberId != undefined){
		(typeof req.body.memberId != 'string') ? (like.memberId = req.body.memberId) : (like.memberId = req.body.memberId.trim());
	}
	if(req.body.status != undefined){
		(typeof req.body.status != 'string') ? (like.status = req.body.status) : (like.status = req.body.status.trim());
	}
	if(req.body.createTime != undefined){
		(typeof req.body.createTime != 'string') ? (like.createTime = req.body.createTime) : (like.createTime = req.body.createTime.trim());
	}
	if(req.body.updateTime != undefined){
		(typeof req.body.updateTime != 'string') ? (like.updateTime = req.body.updateTime) : (like.updateTime = req.body.updateTime.trim());
	}
	if(req.body.bak1 != undefined){
		(typeof req.body.bak1 != 'string') ? (like.bak1 = req.body.bak1) : (like.bak1 = req.body.bak1.trim());
	}
	if(req.body.bak2 != undefined){
		(typeof req.body.bak2 != 'string') ? (like.bak2 = req.body.bak2) : (like.bak2 = req.body.bak2.trim());
	}
	if(req.body.bak3 != undefined){
		(typeof req.body.bak3 != 'string') ? (like.bak3 = req.body.bak3) : (like.bak3 = req.body.bak3.trim());
	}
	if(req.body.bak4 != undefined){
		(typeof req.body.bak4 != 'string') ? (like.bak4 = req.body.bak4) : (like.bak4 = req.body.bak4.trim());
	}
	if(req.body.bak5 != undefined){
		(typeof req.body.bak5 != 'string') ? (like.bak5 = req.body.bak5) : (like.bak5 = req.body.bak5.trim());
	}
	return like;
};

like.initGetReq = function(req){
	var like = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (like.id = req.query.id) : (like.id = req.query.id.trim());
	}
	if(req.query.articleId != undefined){	
		(typeof req.query.articleId != 'string') ? (like.articleId = req.query.articleId) : (like.articleId = req.query.articleId.trim());
	}
	if(req.query.memberId != undefined){	
		(typeof req.query.memberId != 'string') ? (like.memberId = req.query.memberId) : (like.memberId = req.query.memberId.trim());
	}
	if(req.query.status != undefined){	
		(typeof req.query.status != 'string') ? (like.status = req.query.status) : (like.status = req.query.status.trim());
	}
	if(req.query.createTime != undefined){	
		(typeof req.query.createTime != 'string') ? (like.createTime = req.query.createTime) : (like.createTime = req.query.createTime.trim());
	}
	if(req.query.updateTime != undefined){	
		(typeof req.query.updateTime != 'string') ? (like.updateTime = req.query.updateTime) : (like.updateTime = req.query.updateTime.trim());
	}
	if(req.query.bak1 != undefined){	
		(typeof req.query.bak1 != 'string') ? (like.bak1 = req.query.bak1) : (like.bak1 = req.query.bak1.trim());
	}
	if(req.query.bak2 != undefined){	
		(typeof req.query.bak2 != 'string') ? (like.bak2 = req.query.bak2) : (like.bak2 = req.query.bak2.trim());
	}
	if(req.query.bak3 != undefined){	
		(typeof req.query.bak3 != 'string') ? (like.bak3 = req.query.bak3) : (like.bak3 = req.query.bak3.trim());
	}
	if(req.query.bak4 != undefined){	
		(typeof req.query.bak4 != 'string') ? (like.bak4 = req.query.bak4) : (like.bak4 = req.query.bak4.trim());
	}
	if(req.query.bak5 != undefined){	
		(typeof req.query.bak5 != 'string') ? (like.bak5 = req.query.bak5) : (like.bak5 = req.query.bak5.trim());
	}
	return like;
};


module.exports = like;
